using System;
using System.Globalization;

namespace Slf.Samples.SimpleMessages
{
  internal class Program
  {
    private static void Main(string[] args)
    {
      //configure a logger (log the message to the console)
      PrepareLogger();

      //log different messages
      LogMessages();

      Console.ReadLine();
    }


    private static void LogMessages()
    {
      //get logger 
      var logger = LoggerService.GetLogger();

      //log a simple string
      logger.Info("This is an information");
      LineBreak();

      //format output on the fly
      DayOfWeek date = DateTime.Now.DayOfWeek;
      TimeSpan time = DateTime.Now.TimeOfDay;
      logger.Info("Today is {0}. Time is: {1}", date, time);
      LineBreak();

      //format output with a format provider
      CultureInfo culture = new CultureInfo("de-de");
      logger.Info(culture, "DateTime.Now German Format: {0}", DateTime.Now);
      culture = new CultureInfo("en-us");
      logger.Info(culture, "DateTime.Now US Format:     {0}", DateTime.Now);
      LineBreak();

      //log on different levels
      logger.Warn("This is a warning,");
      logger.Error("This is an error.");
      logger.Fatal("This is a fatal error.");
      logger.Debug("This is a debug message.");
    }


    /// <summary>
    /// Initializes the logger to be used.
    /// </summary>
    private static void PrepareLogger()
    {
      //write to the console
      var logger = new DelegateLogger(item => Console.Out.WriteLine(item.LogLevel + ": " + item.Message));

      //plug in the logger
      LoggerService.SetLogger(logger);
    }


    private static void LineBreak()
    {
      Console.Out.WriteLine("\n");
    }
  }
}